%----------------------------------------------------
% Filter for MMG signals
% Edited : 14/01/2013
%----------------------------------------------------
%% Import Initial Data

Rdata= dlmread('3.csv',',',2,0); %Raw data
l= length(data);
x= Rdata(:,1);
y= Rdata(:,2);
data= y - mean (y); % Normalised data
subplot(3,1,1)
plot (x,data)
xlabel('Time(s)')
ylabel('Amplitude (V)')

%% Filter Details

fs = 400; %Sampling frequency
samplePeriod = 1/fs;
Fc = 2; %cut off frequency

%% First Order Butterworth High Pass Filter

w = (2*Fc)/(1/samplePeriod); %Normalised frequency. RBW's defination

[b, a] = butter(1, w, 'high');

newy = filtfilt(b, a, data);
subplot(3,1,2)
plot(x,newy);
xlabel('Time(s)')
ylabel(' Filtered Amplitude (V)')

subplot(3,1,3)
plot (x,data)
hold on
plot(x,newy,'r-');
xlabel('Time(s)')
ylabel('Amplitude (V)')

% End
hold off